import { fileURLToPath, URL } from 'node:url'

import { defineConfig, UserConfigExport, ConfigEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { viteMockServe } from 'vite-plugin-mock'

const project_name = 'vue1' // 项目名称
const project_out_dir = './' // 项目输出目录
// https://vite.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport =>
  defineConfig({
    plugins: [
      vue(),
      vueJsx(),
      vueDevTools(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      viteMockServe({
        mockPath: 'src/mock', // 存放模拟接口的目录 :contentReference[oaicite:11]{index=11}
        enable: command === 'serve', // 仅开发模式启用 :contentReference[oaicite:3]{index=3}
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    base: `/${project_name}/`,
    build: {
      outDir: project_out_dir + project_name,
    },
  })
